<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    var db;
    var objectStore;
    var request = window.indexedDB.open(databaseName, version);

    request.onerror = function (event) {};
    request.onsuccess = function (event) {
        db = request.result//可以拿到数据库对象
    };

    //如果指定的版本号，大于数据库的实际版本号，就会发生数据库升级事件upgradeneeded
    request.onupgradeneeded = function (event) {
        db = event.target.result;
        if (!db.objectStoreNames.contains('person')) { // 判断是否存在
            objectStore = db.createObjectStore('person', { keyPath: 'id' });
            //自动生成主键db.createObjectStore(
            //  'person',
            //  { autoIncrement: true }
            //);
        }

        //新建索引，参数索引名称、索引所在的属性、配置对象
        objectStore.createIndex('email', 'email', { unique: true });
    }
</script>
</body>
</html>